package com.hsource.doctorcenter.service.doctor.impl;

import cn.hutool.core.convert.Convert;
import com.hsource.doctorcenter.conf.dataSource.aspect.SnowflakeIdWorker;
import com.hsource.doctorcenter.domain.doctor.DoctorPrice;
import com.hsource.doctorcenter.mapper.DoctorPriceMapper;
import com.hsource.doctorcenter.service.doctor.IDoctorPriceService;
import com.hsource.doctorcenter.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 医生咨询价格Service业务层处理
 *
 * @author yangyang
 * @date 2020-09-24
 */
@Service
public class DoctorPriceServiceImpl implements IDoctorPriceService {
    @Autowired
    private DoctorPriceMapper doctorPriceMapper;

    /**
     * 查询医生咨询价格
     *
     * @param id 医生咨询价格ID
     * @return 医生咨询价格
     */
    @Override
    public DoctorPrice selectDoctorPriceById(String id) {
        return doctorPriceMapper.selectDoctorPriceById(id);
    }

    /**
     * 查询医生咨询价格列表
     *
     * @param doctorPrice 医生咨询价格
     * @return 医生咨询价格
     */
    @Override
    public List<DoctorPrice> selectDoctorPriceList(DoctorPrice doctorPrice) {
        return doctorPriceMapper.selectDoctorPriceList(doctorPrice);
    }

    /**
     * 根据医生id查询医生价格信息
     * @param doctorPrice
     * @return
     */
    @Override
    public DoctorPrice selectDoctorPriceByDoctorId(DoctorPrice doctorPrice){
        return doctorPriceMapper.selectDoctorPriceByDoctorId(doctorPrice);
    }

    /**
     * 新增医生咨询价格
     *
     * @param doctorPrice 医生咨询价格
     * @return 结果
     */
    @Override
    public int insertDoctorPrice(DoctorPrice doctorPrice) {
        if(StringUtils.isBlank(doctorPrice.getId())) {
            SnowflakeIdWorker idWorker = new SnowflakeIdWorker(1, 1);
            long l = idWorker.nextId();
            doctorPrice.setId(String.valueOf(l));
        }
        return doctorPriceMapper.insertDoctorPrice(doctorPrice);
    }

    /**
     * 修改医生咨询价格
     *
     * @param doctorPrice 医生咨询价格
     * @return 结果
     */
    @Override
    public int updateDoctorPrice(DoctorPrice doctorPrice) {
        return doctorPriceMapper.updateDoctorPrice(doctorPrice);
    }

    /**
     * 删除医生咨询价格对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteDoctorPriceByIds(String ids) {
        return doctorPriceMapper.deleteDoctorPriceByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除医生咨询价格信息
     *
     * @param id 医生咨询价格ID
     * @return 结果
     */
    @Override
    public int deleteDoctorPriceById(String id) {
        return doctorPriceMapper.deleteDoctorPriceById(id);
    }


    /**
     * 根据医生id删除价格信息
     * @param doctorId
     * @return
     */
    @Override
    public int deleteDoctorPriceByDoctorId(String doctorId){
        return doctorPriceMapper.deleteDoctorPriceByDoctorId(doctorId);
    }
}
